package com.longxi.tianjintianbao.ui.presenter.complaint;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.ComplaintListPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.complaint.ComplaintListFragment;
import com.longxi.tianjintianbao.ui.view.complaint.IComplaintListAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class ComplaintListAtPresenter extends BasePresenter<IComplaintListAtView> {

    private ComplaintListPagerAdapter complaintListPagerAdapter;

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("未立项");
        mCategoryList.add("未处理");
        mCategoryList.add("处理中");
        mCategoryList.add("已处理");
        mCategoryList.add("已回访");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public ComplaintListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        mContext.setTitle("投诉处理");
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        initVariable();
    }

    public void initViewPager(){
        complaintListPagerAdapter = new ComplaintListPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList());
        getView().getViewPager().setAdapter(complaintListPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setTabSpaceEqual(true);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void refreshFragmentUi() {
        ComplaintListFragment complaintListFragment = (ComplaintListFragment) complaintListPagerAdapter.getCurrentFragment();
        complaintListFragment.refreshReceiptList();
    }

    @Override
    public void detachView() {
        super.detachView();
        this.complaintListPagerAdapter = null;
    }
}
